//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _MODEL_ROOT_H
#define _MODEL_ROOT_H
//
#include <global.h>
#include <common/id.h>
#include <common/identified_fwd.h>
#include <common/iddictionary.h>
#include <common/restoreerror.h>
#include <common/restorestream.h>
#include "particletemplate_fwd.h"
#include "emittertemplate_fwd.h"
#include "shooter_fwd.h"
#include "group_fwd.h"
//
namespace model
{
class Root:public QObject
{
   Q_OBJECT
   Q_DISABLE_COPY(Root)
//structures
public:
   typedef QList<Identified*> IdentifiedList;
   typedef QHash<Identified*,IdentifiedList> ContainmentType;
//construction
public:
   Root(QObject *p_parent=0);
   ~Root();
   void delete_contents();
//data
public:
   QSet<ParticleTemplate*> particle_templates;
   QSet<EmitterTemplate*> emitter_templates;
   QSet<Shooter*> shooters;
   QSet<Group*> groups;
   Group *root_group;
   ContainmentType child;
   ContainmentType parent;
//data access
public:
   void store_data(QDataStream &p_stream) const;
   void restore_data(RestoreStream &p_stream);
//util
public:
   void test_invariant() const;
//data helpers
public:
   static QString get_object_name(const Identified &p_object);
   IdentifiedList get_children(const Identified &p_object) const;
   IdentifiedList get_parents(const Identified &p_object) const;
   Identified *get_parent(const Identified &p_object) const;
   bool test_containment(const Identified &p_parent,const Identified &p_child) const;
};
}
//
#endif
